package com.cl.ks.config;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;

/**
 * @author chenyitao
 * @date 2021/4/19
 */
@Configuration
public class DatabaseConfig {


    private final ValueConfig valueConfig;

    public DatabaseConfig(ValueConfig valueConfig) {
        this.valueConfig = valueConfig;
    }

    @Bean("base")
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource dbDataSource() {
        return DruidDataSourceBuilder.create().build();
    }
    @PostConstruct
    public void setProperties(){
        System.setProperty("druid.mysql.usePingMethod","false");
    }

}
